package com.lxb.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lxb.commonutils.R;
import com.lxb.eduservice.entity.EduCourse;
import com.lxb.eduservice.entity.EduTeacher;
import com.lxb.eduservice.service.EduCourseService;
import com.lxb.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 前台控制层,首页
 *
 * @author xuebin.li
 * @createTime 2022/12/13 13:00
 */
@Api(description = "前台控制层，首页")
@RestController
@RequestMapping("/eduservice/indexFront")
//@CrossOrigin
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;

    @ApiOperation("获取前八条热门课程,获取前四个名师")
    @GetMapping("/idnex")
    public R index(){

        //查询访问量最高前八课程信息
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("view_count");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(courseQueryWrapper);

        //查询前四个名师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teachers = teacherService.list(teacherQueryWrapper);


        return R.ok().data("courseList",courseList).data("teacherList",teachers);
    }

}
